<?php

/**
 * Created by admin.
 * User: admin
 * Date: 14/3/13
 * Time: 1:54 PM
 * To change this template use File | Settings | File Templates.
 */
class Post extends AppModel {
    public $useTable = 'posts';
    public $name = 'Post';
    
    
    public $belongsTo = array(
        'Catalogue' => array(
            'conditions' => array(
                'Catalogue.status' => 1,
            ),
            'className' => 'Catalogue',
            'foreignKey' => 'cat_id'
        )
    );

    public function listImagesHot($type = array()) {
        $listImagesHot = $this->find('all', array(
            'conditions' => array(
                'Post.status' => 1,
                'Post.images <>' => null,
                'Post.cat_id' => $type
            ),
            'order' => 'Post.order ASC',
            'limit' => 1
            ));
        return $listImagesHot;
    }
    
    public function listVideoHot($type = array()) {
        $listImagesHot = $this->find('all', array(
            'conditions' => array(
                'Post.status' => 1,
                'Post.content <>' => null,
                'Post.cat_id' => $type
            ),
            'order' => 'Post.order ASC',
            'limit' => 1
            ));
        return $listImagesHot;
    }
    
    public function listAlbum($type = array()) {
        $listImagesHot = $this->find('all', array(
            'conditions' => array(
                'Post.status' => 1,
                'Post.cat_id' => $type
            ),
            'order' => 'Post.order ASC',
            'limit' => 20
            ));
        return $listImagesHot;
    }
    
    public function multiMenuProduct($parentid = null, $trees = array()) {
        $trees[] = $parentid;
        $parmenu = $this->Catalogue->find('all', array(
            'conditions' => array(
                'Catalogue.parent_id' => $parentid,
                'Catalogue.status' => 1
            ),
        ));
        if ($parmenu) {
            foreach ($parmenu as $field) {
                $trees = $this->multiMenuProduct($field['Catalogue']['id'], $trees);
            }
        }
        return $trees;
    }

}
